home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / kernel / fsutil / fsutil.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-19  |  10.8 KB  |  293 lines

  1. /*
  2.  * fsutil.h --
  3.  *
  4.  *    Declarations of utility routines used by all the file system modules.
  5.  *    This file defines handle types and some sub-structures
  6.  *    that are embedded in various types of handles.  A
  7.  *    "handle" is a data structure that corresponds one-for-one
  8.  *    with a file system object, i.e. a particular file, a device,
  9.  *    a pipe, or a pseudo-device.  A handle is not always one-for-one
  10.  *    with a file system name.  Devices can have more than one name,
  11.  *    and pseudo-devices have many handles associated with one name.
  12.  *    Each handle is identfied by a unique Fs_FileID, and has a standard
  13.  *    header for manipulation by generic routines.
  14.  *
  15.  * Copyright 1989 Regents of the University of California
  16.  * Permission to use, copy, modify, and distribute this
  17.  * software and its documentation for any purpose and without
  18.  * fee is hereby granted, provided that the above copyright
  19.  * notice appear in all copies.  The University of California
  20.  * makes no representations about the suitability of this
  21.  * software for any purpose.  It is provided "as is" without
  22.  * express or implied warranty.
  23.  *
  24.  * $Header: /cdrom/src/kernel/Cvsroot/kernel/fsutil/fsutil.h,v 9.19 92/12/13 18:18:35 mgbaker Exp $ SPRITE (Berkeley)
  25.  */
  26.  
  27. #ifndef _FSUTIL
  28. #define _FSUTIL
  29.  
  30. #include <stdlib.h>
  31.  
  32. #ifdef KERNEL
  33. #include <fs.h>
  34. #include <fsconsist.h>
  35. #include <hash.h>
  36. #include <proc.h>
  37. #include <vm.h>
  38. #include <rpc.h>
  39. #include <timer.h>
  40. #else
  41. #include <kernel/fs.h>
  42. #include <kernel/fsconsist.h>
  43. #include <kernel/hash.h>
  44. #include <kernel/proc.h>
  45. #include <kernel/vm.h>
  46. #include <kernel/rpc.h>
  47. #include <kernel/timer.h>
  48. #endif
  49. /* constants */
  50. /*
  51.  * Define the types of files that we care about in the kernel, for such
  52.  * things as statistics gathering, write-through policy, etc.  There is not
  53.  * necessarily a one-to-one mapping between these and the types defined
  54.  * in user/fs.h as FS_USER_TYPE_*; for example, FS_USER_TYPE_BINARY and
  55.  * FS_USER_TYPE_OBJECT were mapped into FSUTIL_FILE_TYPE_DERIVED before they
  56.  * were separated into two categories.  It would be possible to flag other
  57.  * derived files (text formatting output, for example) to be in the DERIVED
  58.  * category as well.  
  59.  */
  60. #define FSUTIL_FILE_TYPE_TMP 0
  61. #define FSUTIL_FILE_TYPE_SWAP 1
  62. #define FSUTIL_FILE_TYPE_DERIVED 2
  63. #define FSUTIL_FILE_TYPE_BINARY 3
  64. #define FSUTIL_FILE_TYPE_OTHER 4
  65.  
  66. /*
  67.  * How often to try rewriting a file.
  68.  */
  69. #define    FSUTIL_WRITE_RETRY_INTERVAL    30
  70.  
  71. /* data structures */
  72.  
  73. /*
  74.  * Files or devices with remote I/O servers need to keep some recovery
  75.  * state to handle recovery after their server reboots.
  76.  */
  77.  
  78. typedef struct Fsutil_RecoveryInfo {
  79.     Sync_Lock        lock;        /* This struct is monitored */
  80.     Sync_Condition    reopenComplete;    /* Notified when the handle has been
  81.                      * re-opened at the I/O server */
  82.     int            flags;        /* defined in fsRecovery.c */
  83.     ReturnStatus    status;        /* Recovery status */
  84.     Fsio_UseCounts        use;        /* Client's copy of use state */
  85. } Fsutil_RecoveryInfo;
  86.  
  87. /*
  88.  * Statistics for testing recovery.
  89.  */
  90. typedef    struct    Fsutil_FsRecovNamedStats {
  91.     Fs_FileID        fileID;            /* Unique id for object. */
  92.     Boolean        streamHandle;        /* Is this a stream handle? */
  93.     int            mode;            /* Mode of stream. */
  94.     int            refCount;        /* Ref count on IO handle. */
  95.     int            streamRefCount;        /* Ref count on stream. */
  96.     int            numBlocks;        /* Number of blocks in cache. */
  97.     int            numDirtyBlocks;        /* Number dirty cache blocks. */
  98.     char        name[50];        /* Name of object. */
  99. } Fsutil_FsRecovNamedStats;
  100.  
  101.  
  102. /*
  103.  * For bulk reopen rpc's -- reopening more than one handle at a time
  104.  * per rpc -- this is the information sent to the server per handle.
  105.  *
  106.  * The reopenParams field is rather bogusly set to a size larger than
  107.  * Fsio_FileReopenParams,
  108.  * just because that's the reopenParam that requires the most space.  The
  109.  * field is really a generic reopenParams for all the stream types.  Yeah,
  110.  * this isn't safe, but mentioning the type names here gives a circular
  111.  * loop in the header files.
  112.  */
  113. typedef struct Fsutil_BulkHandle {
  114.     int                type;        /* Type of handle. */
  115.     int                serverID;    /* For checking on other end. */
  116.     Fs_HandleHeader        *hdrPtr;    /* Ptr to hdr for handle. */
  117.                         /* Valid only on client. */
  118.     char            reopenParams[14 * 4];
  119.                         /* Reopen info for server. */
  120. } Fsutil_BulkHandle;
  121.  
  122. /*
  123.  * For bulk reopen rpc's, this is the information returned to the client
  124.  * from the server for each handle.
  125.  *
  126.  * Here too the state field is rather bogusly set to a size larger than that
  127.  * for Fsio_FileState, since the other handle types don't need as much space.
  128.  */
  129. typedef struct Fsutil_BulkReturn {
  130.     ReturnStatus    status;        /* Handle reopen status from server. */
  131.     char        state[18 * 4];    /* Info returned from server. */
  132. } Fsutil_BulkReturn;
  133.  
  134. /*
  135.  * Operations per stream type to be called for setting up and finishing
  136.  * off handles to be reopened.
  137.  */
  138. typedef struct Fsutil_BulkReopenOps {
  139.     ReturnStatus    (*setup) _ARGS_((Fs_HandleHeader *hdrPtr,
  140.                             Address paramsPtr));
  141.     void        (*finish) _ARGS_((Fs_HandleHeader *hdrPtr,
  142.                             Address statePtr,
  143.                             ReturnStatus status));
  144. } Fsutil_BulkReopenOps;
  145.  
  146.  
  147. extern Boolean fsconsist_Debug;
  148. /*
  149.  * Whether or not to flush the cache at regular intervals.
  150.  */
  151.  
  152. extern Boolean fsutil_ShouldSyncDisks;
  153.  
  154. extern    int    fsutil_NumRecovering;
  155.  
  156. /* procedures */
  157. /*
  158.  * Fsutil_StringNCopy
  159.  *
  160.  *    Copy the null terminated string in srcStr to destStr and return the
  161.  *    actual length copied in *strLengthPtr.  At most numBytes will be
  162.  *    copied if the string is not null-terminated.
  163.  */
  164.  
  165. #define    Fsutil_StringNCopy(numBytes, srcStr, destStr, strLengthPtr) \
  166.     Proc_StringNCopy(numBytes, srcStr, destStr, strLengthPtr)
  167.  
  168. /*
  169.  * Macros to handle type casting when dealing with handles.
  170.  */
  171. #define Fsutil_HandleFetchType(type, fileIDPtr) \
  172.     (type *)Fsutil_HandleFetch(fileIDPtr)
  173.  
  174. #define Fsutil_HandleDupType(type, handlePtr) \
  175.     (type *)Fsutil_HandleDup((Fs_HandleHeader *)handlePtr)
  176.  
  177. #define Fsutil_HandleLock(handlePtr) \
  178.     Fsutil_HandleLockHdr((Fs_HandleHeader *)handlePtr)
  179.  
  180. #define Fsutil_HandleUnlock(handlePtr) \
  181.     (void)Fsutil_HandleUnlockHdr((Fs_HandleHeader *)handlePtr)
  182.  
  183. #define Fsutil_HandleRelease(handlePtr, locked) \
  184.     Fsutil_HandleReleaseHdr((Fs_HandleHeader *)handlePtr, locked)
  185.  
  186. #define Fsutil_HandleRemove(handlePtr) \
  187.     Fsutil_HandleRemoveHdr((Fs_HandleHeader *)handlePtr)
  188.  
  189. #define Fsutil_HandleName(handlePtr) \
  190.     ((((Fs_HandleHeader *)handlePtr) == (Fs_HandleHeader *)NIL) ? \
  191.         "(no handle)": \
  192.       ((((Fs_HandleHeader *)handlePtr)->name == (char *)NIL) ? "(no name)" : \
  193.     ((Fs_HandleHeader *)handlePtr)->name) )
  194.  
  195. #define    Fsutil_TimeInSeconds()    (Timer_GetUniversalTimeInSeconds())
  196.  
  197. #define mnew(type)    (type *)malloc(sizeof(type))
  198.  
  199. extern void Fsutil_RecoveryInit _ARGS_((Fsutil_RecoveryInfo *recovPtr));
  200. extern void Fsutil_RecoverySyncLockCleanup _ARGS_((
  201.         Fsutil_RecoveryInfo *recovPtr));
  202. extern void Fsutil_WantRecovery _ARGS_((Fs_HandleHeader *hdrPtr));
  203. extern void Fsutil_AttemptRecovery _ARGS_((ClientData data, 
  204.         Proc_CallInfo *callInfoPtr));
  205. extern ReturnStatus Fsutil_WaitForRecovery _ARGS_((Fs_HandleHeader *hdrPtr, 
  206.         ReturnStatus rpcStatus));
  207. extern Boolean Fsutil_RecoveryNeeded _ARGS_((Fsutil_RecoveryInfo *recovPtr));
  208. extern void Fsutil_Reopen _ARGS_((int serverID, ClientData clientData));
  209. extern Boolean Fsutil_RemoteHandleScavenge _ARGS_((Fs_HandleHeader *hdrPtr));
  210. extern void Fsutil_ClientCrashed _ARGS_((int spriteID, ClientData clientData));
  211. extern void Fsutil_ClientCrashed _ARGS_((int spriteID, ClientData clientData));
  212. extern void Fsutil_RemoveClient _ARGS_((int clientID));
  213.  
  214.  
  215. /*
  216.  * Wait list routines.  Waiting lists for various conditions are kept
  217.  * hanging of I/O handles.
  218.  */
  219. extern void Fsutil_WaitListInsert _ARGS_((List_Links *list, 
  220.         Sync_RemoteWaiter *waitPtr));
  221. extern void Fsutil_WaitListNotify _ARGS_((List_Links *list));
  222. extern void Fsutil_FastWaitListInsert _ARGS_((List_Links *list, 
  223.         Sync_RemoteWaiter *waitPtr));
  224. extern void Fsutil_FastWaitListNotify _ARGS_((List_Links *list));
  225. extern void Fsutil_WaitListDelete _ARGS_((List_Links *list));
  226. extern void Fsutil_WaitListRemove _ARGS_((List_Links *list, 
  227.         Sync_RemoteWaiter *waitPtr));
  228.  
  229. /*
  230.  * File handle routines.
  231.  */
  232. extern void Fsutil_HandleInit _ARGS_((int fileHashSize));
  233. extern Boolean Fsutil_HandleInstall _ARGS_((Fs_FileID *fileIDPtr, 
  234.     int size, char *name, Boolean cantBlock, Fs_HandleHeader **hdrPtrPtr));
  235. extern Fs_HandleHeader *Fsutil_HandleFetch _ARGS_((Fs_FileID *fileIDPtr));
  236. extern Fs_HandleHeader *Fsutil_HandleFetchNoWait _ARGS_((Fs_FileID *fileIDPtr,
  237.                         Boolean *wouldWaitPtr));
  238. extern Fs_HandleHeader *Fsutil_HandleDup _ARGS_((Fs_HandleHeader *hdrPtr));
  239. extern Fs_HandleHeader *Fsutil_GetNextHandle _ARGS_((Hash_Search *hashSearchPtr));
  240. extern void Fsutil_HandleLockHdr _ARGS_((Fs_HandleHeader *hdrPtr));
  241. extern void Fsutil_HandleIncRefCount _ARGS_((Fs_HandleHeader *hdrPtr,
  242.         int amount));
  243. extern void Fsutil_HandleDecRefCount _ARGS_((Fs_HandleHeader *hdrPtr));
  244. extern void Fsutil_HandleInvalidate _ARGS_((Fs_HandleHeader *hdrPtr));
  245. extern Boolean Fsutil_HandleValid _ARGS_((Fs_HandleHeader *hdrPtr));
  246. extern Boolean Fsutil_HandleUnlockHdr _ARGS_((Fs_HandleHeader *hdrPtr));
  247. extern void Fsutil_HandleReleaseHdr _ARGS_(( Fs_HandleHeader *hdrPtr, 
  248.         Boolean locked));
  249. extern void Fsutil_HandleRemoveHdr _ARGS_((Fs_HandleHeader *hdrPtr));
  250. extern Boolean Fsutil_HandleAttemptRemove _ARGS_((Fs_HandleHeader *hdrPtr));
  251. extern void Fsutil_HandleRemoveInt _ARGS_((Fs_HandleHeader *hdrPtr));
  252. /*
  253.  * Miscellaneous.
  254.  */
  255. extern void Fsutil_FileError _ARGS_((Fs_HandleHeader *hdrPtr, char *string, 
  256.         int status));
  257. extern void Fsutil_PrintStatus _ARGS_((int status));
  258. extern char *Fsutil_FileTypeToString _ARGS_((int type));
  259.  
  260. extern ReturnStatus Fsutil_DomainInfo _ARGS_((Fs_FileID *fileIDPtr, 
  261.         Fs_DomainInfo *domainInfoPtr));
  262.  
  263. extern int Fsutil_HandleDescWriteBack _ARGS_((Boolean shutdown, int domain));
  264. extern void Fsutil_SyncProc _ARGS_((ClientData data, 
  265.         Proc_CallInfo *callInfoPtr));
  266. extern void Fsutil_Sync _ARGS_((unsigned int writeBackTime, Boolean shutdown));
  267. extern void Fsutil_SyncStub _ARGS_((ClientData data));
  268. extern ReturnStatus Fsutil_WaitForHost _ARGS_((Fs_Stream *streamPtr, int flags,
  269.         ReturnStatus rpcStatus));
  270.  
  271. extern ReturnStatus Fsutil_RpcRecovery _ARGS_((ClientData srvToken, 
  272.         int clientID, int command, Rpc_Storage *storagePtr));
  273.  
  274. extern void Fsutil_HandleScavengeStub _ARGS_((ClientData data));
  275. extern void Fsutil_HandleScavenge _ARGS_((ClientData data, 
  276.         Proc_CallInfo *callInfoPtr));
  277.  
  278. extern char *Fsutil_GetFileName _ARGS_((Fs_Stream *streamPtr));
  279.  
  280. extern ReturnStatus Fsutil_FsRecovInfo _ARGS_((int length, 
  281.         Fsutil_FsRecovNamedStats *resultPtr, int *lengthNeededPtr));
  282.  
  283. extern int Fsutil_TestForHandles _ARGS_((int serverID));
  284.  
  285. extern void Fsutil_ZeroHandleStats _ARGS_((void));
  286. extern void Fsutil_InitBulkReopenOps _ARGS_((int type,
  287.     Fsutil_BulkReopenOps *reopenOpsPtr));
  288.     
  289. extern ReturnStatus Fsutil_DoServerRecovery _ARGS_((int clientID));
  290. extern void Fsutil_InitBulkReopenTables _ARGS_((void));
  291.  
  292. #endif /* _FSUTIL */
  293.